import os
import sys
import unittest
# 获取项目根目录的绝对路径
project_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# 将项目根目录添加到 Python 路径
sys.path.append(project_root)

from func.writer.writer_func import *

class TestLiteratureReviewWriter(unittest.TestCase):
    def setUp(self):
        self.writer = LiteratureReviewWriter()
        self.searchCore = SearchCore()

    def test_write_subsections_content(self):
        # 准备测试数据
        context_variables = {
            "title": "大语言模型的发展",
            "section_title": "技术基础", 
            "sub_section_title": "Agent"
        }
        
        structure = """
        # 大语言模型的发展
        
        ## 技术基础
        ### 注意力机制
        ### Transformer架构
        
        ## 发展现状
        ### 预训练模型
        ### 微调技术
        """
        
        # 执行测试
        result = self.writer.write_subsections_content(
            context_variables,
            structure,
            word_num=300
        )
        print(result)
    
    def test_get_reference_content(self):
        """测试获取参考文献内容的功能"""
        # 准备测试数据
        query = "Text2SQL translation with large language models"
        threshold = 0.6
        top_k = 5
        
        # 执行测试
        result = self.writer.get_reference_content(query, threshold, top_k)
            
        # 打印测试结果以便查看
        print(f"\n获取到{len(result)}篇参考文献:")
        for i, item in enumerate(result, 1):
            print(f"\n文献{i}:")
            print(f"标题: {item['title']}")
            print(f"内容长度: {len(item['content'])}字符")
        
    def test_searchCore(self):
        query = "Text2SQL translation with large language models"
        result = self.searchCore.search_konwledge_content(query)
        print(result)

if __name__ == '__main__':
    suite = unittest.TestSuite()
    suite.addTest(TestLiteratureReviewWriter('test_write_subsections_content'))
    # 运行测试套件
    unittest.TextTestRunner().run(suite)
    